package com.zjd.swing.browser;

import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationParameters;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: ${description}
 * @Author: sobey
 * @Email: sobey178@163.com
 * @Date: 2022/3/26 23:29
 */
public class MyBrowserJPanel extends JPanel{
    private static final long serialVersionUID = 1L;
    private JPanel webBrowserPanel;
    public JWebBrowser webBrowser;

    public MyBrowserJPanel(String url){
        super(new BorderLayout());
        WebBrowserNavigationParameters parameters = new WebBrowserNavigationParameters();
        Map<String, String> keyValueMap = new HashMap<>();
        keyValueMap.put("User-Agent", "dj-native-swing");
        parameters.setHeaders(keyValueMap);

        webBrowserPanel = new JPanel(new BorderLayout());
        webBrowser = new JWebBrowser();
//        webBrowser.navigate(url);
        webBrowser.navigate(url, parameters);
        webBrowser.setButtonBarVisible(false);
        webBrowser.setMenuBarVisible(false);
        webBrowser.setBarsVisible(false);
        webBrowser.setStatusBarVisible(false);
        webBrowser.addWebBrowserListener(new MyWebBrowserListener());
        webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
        add(webBrowserPanel, BorderLayout.CENTER);
    }
}
